@extends('backstage.layout.master')
@section('title', '产品模板定制区域列表')
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a target="_blank" href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a target="_blank" href="/backstage/product-temp/product-temp-list">产品模板</a>
            </li>
            <li>
                设计区域列表
            </li>
        </ul><!-- .breadcrumb -->

        <div class="nav-search" id="nav-search">
            <form class="form-search">
			<span class="input-icon">
				<input type="text" placeholder="搜索..." name="search" value="{{isset($prod_temps->search)?$prod_temps->search:''}}" class="nav-search-input"
                                           id="nav-search-input" autocomplete="off"/>
				<i class="icon-search nav-search-icon"></i>
				</span>
            </form>
        </div><!-- #nav-search -->
    </div>

    <div class="page-content">
        <div class="page-header">
            <h1>
                产品
                <small>
                    <i class="icon-double-angle-right"></i>
                </small>
                <span class="pull-right">
                <button class="btn btn-primary" onclick="javascript:window.location.href='{{asset('')}}backstage/product-temp/add-custom-zone?product_temp_id={{empty($_GET['product_temp_id'])?'':$_GET['product_temp_id']}}&colour_id={{empty($_GET['colour_id'])?'0':$_GET['colour_id']}}';">添加设计区域</button>
                <button class="btn btn-primary" onclick="javascript:window.location.href='{{asset('')}}backstage/product-temp/add-stock?id={{empty($_GET['product_temp_id'])?'':$_GET['product_temp_id']}}';">返回添加库存页</button>
                </span>
            </h1>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <h3 class="header smaller lighter red">产品模板简介：</h3>
                <div class="well">
                    <h4 class="green smaller lighter">产品模板参数</h4>
                    1、产品模板Id：{{isset($product_temp->product_temp_id)?$product_temp->product_temp_id:""}}</br>
                    2、品牌：{{isset($product_temp->brand_name)?$product_temp->brand_name:""}}</br>
                    3、产品模板名称：{{isset($product_temp->name)?$product_temp->name:""}}</br>
                    4、产品模板简介：{{isset($product_temp->description)?$product_temp->description:""}}</br>
                    5、当前颜色：{{isset($temp_colour->colour_name)?$temp_colour->colour_name:""}}</br>
                </div>
            </div>
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="table-responsive">
                    <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th class="center">
                                <label>
                                    <input type="checkbox" class="ace">
                                    <span class="lbl"></span>
                                </label>
                            </th>
                            <th>设计区域编号</th>
                            <th>位置</th>
                            <th>排序</th>
                            <th class="hidden-480">缩略图</th>
                            <th>操作</th>
                        </tr>
                        </thead>

                        <tbody>
                        @foreach ($temp_custom_zones as $custom_zone)
                            <tr class="" data-tr-id="{{$custom_zone->id}}">
                                <td class="center">
                                    <label>
                                        <input type="checkbox" class="ace">
                                        <span class="lbl"></span>
                                    </label>
                                </td>
                                <td>{{isset($custom_zone->id)?$custom_zone->id:''}}</td>
                                <td>
                                    {{isset($custom_zone->position_name)?$custom_zone->position_name:''}}
                                </td>
                                <td style="width:68px;">
                                    <input type="number" name="sort" value="{{isset($custom_zone->sort)?$custom_zone->sort:1}}" class="sort" style="width:50px;">
                                    <input type="hidden" value="{{isset($custom_zone->sort)?$custom_zone->sort:1}}">
                                    <input type="hidden" value="{{isset($custom_zone->id)?$custom_zone->id:''}}">
                                </td>
                                <td class="hidden-480"><img src="{{isset($custom_zone->thumbnail)?$custom_zone->thumbnail:''}}" width="40"></td>
                                <td>
                                    <ul class="nav-pills" style="list-style-type:none">
                                        <li class="dropdown all-camera-dropdown">
                                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                                                <span >操作</span>
                                                <b class="caret"></b></a><ul class="dropdown-menu">
                                                <li data-filter-camera-type="Zed">
                                                    <a target="_blank" href="/backstage/product-temp/update-custom-zone?product_temp_id={{isset($product_temp->product_temp_id)?$product_temp->product_temp_id:""}}&colour_id={{isset($temp_colour->colour_id)?$temp_colour->colour_id:0}}&custom_zone_id={{isset($custom_zone->id)?$custom_zone->id:0}}">
                                                        <span id="">编辑</span>
                                                    </a>
                                                </li>
                                                <li data-filter-camera-type="all">
                                                    <a target="_blank"  href="/backstage/product-temp/craftsmanship-list?custom_zone_id={{isset($custom_zone->id)?$custom_zone->id:''}}&product_temp_id={{isset($product_temp->product_temp_id)?$product_temp->product_temp_id:""}}&colour_id={{isset($temp_colour->colour_id)?$temp_colour->colour_id:0}}">
                                                        <span >工艺列表</span>
                                                    </a>
                                                </li>
                                                <li data-filter-camera-type="all">
                                                    <a  data-delete="{{isset($custom_zone->id)?$custom_zone->id:0}}">
                                                        <span >删除</span>
                                                    </a>
                                                </li>
                                            </ul>
                                        </li>
                                    </ul>
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script type="text/javascript">
        $(function () {
            $('[data-rel=tooltip]').tooltip();
            $('[data-delete]').click(function(){
                var  custom_zone_id = $(this).attr("data-delete");
                if(custom_zone_id!==0){
                    swal({
                        title: "确定删除？？",
                        text: "",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        closeOnConfirm: true,
                        closeOnCancel: true
                    },function (){
                        $.ajax({
                            type: "POST",
                            url: "/backstage/product-temp/del-custom-zone",
                            data: {'custom_zone_id':custom_zone_id},
                            success: function (msg) {
                                if(msg.state=1){
                                    swal({title: "删除成功！", text: "",type: "success", timer:1000 })
                                    $('[data-tr-id='+custom_zone_id+']').remove();
                                }else {
                                    swal({title: msg.message, text: "",type: "error", timer:1000 })
                                }

                            }, error: function () {
                                swal({title: "系统繁忙！", text: "",type: "error", timer:1000 })
                            }
                        });
                    });
                }
            });
            $('table th input:checkbox').on('click' , function(){
                var that = this;
                $(this).closest('table').find('tr > td:first-child input:checkbox')
                        .each(function(){
                            this.checked = that.checked;
                            $(this).closest('tr').toggleClass('selected');
                        });

            });
            $(".sort").blur(function(){
                var sort = $(this).next().val();
                var newSort = $(this).val();
                var custom_zone_id = $(this).next().next().val();
                var a = $(this);
                if(!checkRate(newSort)){
                    swal({
                        title: "输入排序号不在0-999范围内!!！",
                        text: "",
                        type: "error",
                        timer:3000
                    });
                }else if(newSort == sort){
                    return;
                }else{
                    $.ajax({
                        type: "POST",
                        url: "/backstage/product-temp/update-custom-zone-sort",
                        data:{"sort":newSort,"id":custom_zone_id},
                        success: function(msg){
                            if(msg.state==1){
                                swal({
                                    title: "更新成功！",
                                    text: "",
                                    type: "success",
                                    timer:2000
                                });
                                location.reload();
                            }else{
                                swal({
                                    title: msg.message,
                                    text: "",
                                    type: "error",
                                    timer:2000
                                });
                            }
                        },
                        error:function(){
                            swal({
                                title: "系统繁忙！",
                                text: "",
                                type: "error",
                                timer:3000
                            });
                        }
                    });
                }
            });

        });
        /***
         * 检查数据格式
         * @param input
         * @returns {boolean}
         */
        function checkRate(input)
        {
            var reg = new RegExp("^[0-9]{1,3}$");
            return reg.test(input);
        }
    </script>
@stop